package com.hrb.monkey.activity.zxing;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.hrb.monkey.R;
import com.hrb.monkey.activity.base.BaseActivity;
import com.uuzuche.lib_zxing.activity.CodeUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ZxingCreatCodeActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.edit_content)
    EditText editContent;
    @BindView(R.id.button_content)
    Button buttonContent;
    @BindView(R.id.button1_content)
    Button button1Content;
    @BindView(R.id.image_content)
    ImageView imageContent;
    @BindView(R.id.fab)
    FloatingActionButton fab;
    public Bitmap mBitmap = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zxing_creat_code);
        ButterKnife.bind(this);
        button1Content.setOnClickListener(this);
        buttonContent.setOnClickListener(this);


    }

    @Override
    public void onClick(View v) {
        String textContent = editContent.getText().toString();
        if (TextUtils.isEmpty(textContent)) {
            Toast.makeText(this, "您的输入为空!", Toast.LENGTH_SHORT).show();
            return;
        }
        editContent.setText("");
        switch (v.getId()){
            case R.id.button_content:
                mBitmap = CodeUtils.createImage(textContent, 400, 400, BitmapFactory.decodeResource(getResources(), R.drawable.monkey));
                break;
            case R.id.button1_content:
                mBitmap = CodeUtils.createImage(textContent, 400, 400, null);
                break;
        }
        imageContent.setImageBitmap(mBitmap);
    }
}
